package com.hom;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

//本类用于演示Socket编程中的服务器
public class ThreeTest {
    public static void main(String[] args) {
        try{
            ServerSocket ss = new ServerSocket(8899);
            Socket soket = ss.accept();

            BufferedReader br = new BufferedReader(new InputStreamReader(soket.getInputStream()));

            String s = br.readLine();

            System.out.println("你好，客户端，这里是服务器，我收到了你的信息："+s);

            br.close();
            soket.shutdownInput();

            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(soket.getOutputStream()));
            bw.write("你好，客户端，这里是服务器，我收到了你的信息：");
            bw.close();
            soket.close();
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }

}
